package com.mine;

class Solution {
    public static ListNode oddEvenList(ListNode head) {
        if (head == null) {
            return head;
        }
        ListNode dummy1 = new ListNode(0);
        ListNode p1 = dummy1;
        ListNode dummy2 = new ListNode(0);
        ListNode p2 = dummy2;
        int count = 0;
        while (head != null) {
            if (count % 2 == 0) {
                p1.next = head;
                p1 = p1.next;
            } else {
                p2.next = head;
                p2 = p2.next;
            }
            count++;
            head = head.next;
        }
        p2.next = null;
        p1.next = dummy2.next;

        return dummy1.next;
    }

    public static void main(String[] args) {
        ListNode node = new ListNode(1);
        ListNode p = node;
        p.next = new ListNode(2);
        p = p.next;
        p.next = new ListNode(3);
        p = p.next;
        p.next = new ListNode(4);
        p = p.next;
        p.next = new ListNode(5);
        oddEvenList(node);
    }
}

class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}
